package Middle.FindLongestStrLength;

import java.util.ArrayList;
import java.util.List;

public class findLongestStr1 {
    public static void main(String[] args) {
        String str = "pwwkew";
        System.out.println(lengthOfLongestSubstring(str));
    }

    public static int lengthOfLongestSubstring(String str1) {
        char[] chars = str1.toCharArray();
        List<Character> result = new ArrayList<>();
        int max = 0;
        for (char aChar : chars) {
            if (result.contains(aChar)) {
               result = result.subList(result.indexOf(aChar) + 1, result.size());
            }
            result.add(aChar);
            max = Math.max(result.size(), max);
        }
        return max;
    }

}
